# utils/response_utils.py

from flask import jsonify
from utils.time_utils import TimeUtils

class ResponseUtils:
    def success(data=None, message="操作成功", code=200,page=None,pagesize=10):
        """
        返回成功的响应
        :param data: 返回的数据
        :param message: 返回的消息
        :param code: 状态码
        :return: JSON 响应
        """
        response = {
            "code": code,
            "message": message,
            "time": TimeUtils.get_current_time(),
            "data": [data]
        }
        return jsonify(response), code

    def error(message="操作失败", code=400, data=None):
        """
        返回错误的响应
        :param message: 返回的消息
        :param code: 状态码
        :param data: 返回的数据
        :return: JSON 响应
        """
        response = {
            "code": code,
            "message": message,
            "time": TimeUtils.get_current_time(),
            "data": data
        }
        return jsonify(response), code